** Table 3: ECB access: Distance to deposit facility rate
clear

** Loading data
*Include:
*cd // *Your directory path goes here* //
import excel .\Data\GC_DailyAverages_Pseudo.xlsx, firstrow allstring

* Step 1: Organize the data:
gen dateSTATA = date(substr(refdate,1,11),"MDY")
format dateSTATA %td
drop refdate
gen year=year(dateSTATA)
gen month=month(dateSTATA)

destring volweightedrate volsum ecbaccesslender, replace
encode basket, gen(basketcat)
drop basket
label define order  1 ON  2 TN  3 SN
encode term, gen(termcat) label(order)
drop term

gen QE = 0
*start of QE, see: https://www.ecb.europa.eu/mopo/implement/app/html/index.en.html#pspp
replace QE = 1 if dateSTATA > date("08.03.2015","DMY") 

egen panelid = group(basketcat termcat ecbaccesslender)
xtset panelid dateSTATA

* Step 2: Add information on EONIA
* download daily data from, for example, Bloomberg / Thomson Reuters and replace code below:
gen EONIA=0.5 // create pseudodata

* Step 3: Add information on DFR
* download data on the DFR (see: https://www.ecb.europa.eu/stats/policy_and_exchange_rates/key_ecb_interest_rates/html/index.en.html) and replace code below:
gen DFR=0.5 // create pseudodata


* Step 4: Calculate daily, average GC rate
preserve
sort country dateSTATA
by country dateSTATA: egen meanGCRate = wtmean(volweightedrate), weight(volsum)
keep meanGCRate country dateSTATA
duplicates drop
save .\Data\MeanGCRatesByCountry.dta, replace
restore
merge m:1 dateSTATA country using .\Data\MeanGCRatesByCountry.dta
keep if _merge==3
drop _merge
erase .\Data\MeanGCRatesByCountry.dta

gen GCBelowDep = 0
replace GCBelowDep = 1 if meanGCRate<DFR

* Step 5: Calculate changes:
bysort panelid (dateSTATA): gen delrGC = log(volweightedrate[_n]/volweightedrate[_n-1])
bysort panelid (dateSTATA): gen delrGCtm1 = log(volweightedrate[_n-1]/volweightedrate[_n-2])
bysort panelid (dateSTATA): gen delMMRate = log(EONIA[_n]/EONIA[_n-1])

* Step 6: Calculate additional regression inputs:
gen DistanceDFR =(DFR-meanGCRate)
gen Bucket_1 = 0
gen Bucket_2 = 0
gen Bucket_3 = 0
replace Bucket_1 = 1 if DistanceDFR > -0.5 & DistanceDFR <= -0.25
replace Bucket_2 = 1 if DistanceDFR > -0.25 & DistanceDFR <0
replace Bucket_3 = 1 if DistanceDFR >= 0

gen delMMRate_Acc = delMMRate*ecbaccesslender
gen delMMRate_Acc_DistDFR = delMMRate*ecbaccesslender*DistanceDFR
gen delMMRate_AccB1 = delMMRate*ecbaccesslender*Bucket_1
gen delMMRate_AccB2 = delMMRate*ecbaccesslender*Bucket_2
gen delMMRate_AccB3 = delMMRate*ecbaccesslender*Bucket_3

** Regressions

* All
eststo clear
sort termcat
eststo R3a, title("All"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_Acc_DistDFR delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R3b, title("All"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_AccB1 delMMRate_AccB2 delMMRate_AccB3 delrGCtm1, absorb(year##month##termcat) vce(robust) nocons

* Core
keep if (country=="DE"|country=="FR"|country=="BE"|country=="NL"|country=="FI"|country=="AT")
sort termcat
eststo R2a, title("Core"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_Acc_DistDFR delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R2b, title("Core"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_AccB1 delMMRate_AccB2 delMMRate_AccB3 delrGCtm1, absorb(year##month##termcat) vce(robust) nocons

* Germany
keep if (country=="DE")
sort termcat
eststo R1a, title("DE"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_Acc_DistDFR delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
eststo R1b, title("DE"): reghdfe delrGC delMMRate ecbaccesslender delMMRate_Acc delMMRate_AccB1 delMMRate_AccB2 delMMRate_AccB3 delrGCtm1, absorb(year##month##termcat) vce(robust) nocons
